package com.apanal.qlife.common.model;

import java.util.List;

import com.apanal.qlife.common.constants.Constants;
import com.apanal.qlife.common.dictionary.DictionaryMap;
import com.apanal.qlife.org.model.Organization;
import com.apanal.qlife.property.model.Community;
import com.apanal.qlife.sys.model.Area;
import com.apanal.qlife.sys.model.Group;
import com.apanal.qlife.sys.model.Resource;
import com.apanal.qlife.sys.model.Role;
import com.apanal.qlife.sys.model.User;

/**
 * 模型转换类
 * 
 * 
 * @author shuliangxing
 * 
 * @date 2015-8-27下午2:27:20
 */
public class ModelConvert {
	/**
	 * 获得id字符串
	 * 
	 * @param list
	 * @return
	 */
	public static String getIds(List<?> list) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < list.size(); i++) {
			Object obj = list.get(i);
			if (i > 0) {
				sb.append(Constants.SEPARATOR_COMMA_ENUS);
			}
			if (obj instanceof User) {
				sb.append(((User) obj).getUseId());
			} else if (obj instanceof Role) {
				sb.append(((Role) obj).getRolId());
			} else if (obj instanceof Group) {
				sb.append(((Group) obj).getGroId());
			} else if (obj instanceof Resource) {
				sb.append(((Resource) obj).getResId());
			}else if (obj instanceof Organization){
			   sb.append(((Organization) obj).getOrgId());
			}else if (obj instanceof Area){
			   sb.append(((Area) obj).getAreId());
			}else if (obj instanceof Community){
			  sb.append(((Community) obj).getComId());
			}
			
		}
		return sb.toString();
	}

	/**
	 * 获得名称字符串
	 * 
	 * @param list
	 * @return
	 */
	public static String getNames(List<?> list) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < list.size(); i++) {
			Object obj = list.get(i);
			if (i > 0) {
				// 用中文逗号来分隔,layer.tips对全英文内容换行有问题
				sb.append(Constants.SEPARATOR_COMMA_ZHCN);
			}
			if (obj instanceof User) {
				User user = (User) obj;
				sb.append(user.getUseRealName());
				// 增加锁定状态标识
				if (user.getUseLocked() == 1) {
					sb.append("【")
							.append(DictionaryMap.getValue(Constants.LOCK, 1))
							.append("】");
				}
			} else if (obj instanceof Role) {
				Role role = (Role) obj;
				sb.append(role.getRolName());
				// 增加停用状态标识
				if (role.getNormal() == 0) {
					sb.append("【")
							.append(DictionaryMap.getValue(Constants.NORMAL, 0))
							.append("】");
				}
			} else if (obj instanceof Group) {
				Group group = (Group) obj;
				sb.append(group.getGroName());
				// 增加停用状态标识
				if (group.getNormal() == 0) {
					sb.append("【")
							.append(DictionaryMap.getValue(Constants.NORMAL, 0))
							.append("】");
				}
			} else if (obj instanceof Resource) {
				Resource resource = (Resource) obj;
				sb.append(resource.getResName());
				// 增加停用状态标识
				if (resource.getNormal() == 0) {
					sb.append("【")
							.append(DictionaryMap.getValue(Constants.NORMAL, 0))
							.append("】");
				}
			}

		}
		return sb.toString();
	}

}
